<template>
  <div id="app">
    <ul class="body">
      <li
        v-for="(item, index) in list"
        :key="index">
        <div  :is="item.com" v-if="activeIndex == index"></div>
        </li>
    </ul>
    <footer>
      <ol class="foot">
        <li
          v-for="(item, index) in list"
          :key="index"
          @click="activeIndex = index"
          :class="{on:activeIndex==index}"
        >
          {{ item.title }}
        </li>
      </ol>
    </footer>
  </div>
</template>

<script>
import HomePage from "./components/HomePage.vue";
import My from "./components/My";
import Buy from "./components/Buy";
import Service from "./components/Service";
export default {
  name: "App",
  components: {
    HomePage,
    My,
    Buy,
    Service,
    
  },
  data() {
    return {
      list: [
        {
          com: "HomePage",
          title: "首页",
        },
        {
          com: "Buy",
          title: "购买",
        },
        {
          com: "Service",
          title: "服务",
        },
        {
          com: "My",
          title: "我的",
        },
      ],
      activeIndex: 0,
    };
  },
};
</script>

<style>
*{
  margin: 0;
  padding: 0;
  list-style: none;
  box-sizing: border-box;
}
#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.body {
  flex: 1;
  background: #fcc;
}
.foot {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: #cfc;
}
.foot .on {
  color: red;
}
</style>
